package com.yunxun.coinmessage.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import com.baidu.ueditor.ActionEnter;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class UeditorController {
    @RequestMapping("/")
    @ResponseBody
    private ModelAndView showPage(){
         return new ModelAndView("redirect:/coinadmin");

    }

    @Autowired
    private Environment env;
    private String configjsonPath;

    @RequestMapping(value="/config")
    @ResponseBody
    public void config(HttpServletRequest request, HttpServletResponse response) {
        response.setContentType("application/json");
        String rootPath = request.getSession().getServletContext().getRealPath("/");


        try {
            configjsonPath=env.getProperty("configjson.path");
            String exec = new ActionEnter(request, rootPath, configjsonPath).exec();
            PrintWriter writer = response.getWriter();
            writer.write(exec);
            writer.flush();
            writer.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
